function Menu()
{
  var self = this;
  var MENU_CLOSE_MS = 500;
  var ELEMENT_NODE = 1;
  
  this.menuOpen = false;
  this.aNodes = new Array();

  function Node(elRef) {
    this.elRef = elRef;
    this.timeRef = null;
  }
  function isParent(eKind, eVindOuder) {
    var eOudere = eKind.parentNode;
    do {
      eOudere = eOudere.parentNode;
      if (eOudere == eVindOuder)
        return true;
    } while (eOudere.nodeName != 'BODY')
    return false;
  }
  this.showSub = function(showNode) {
    if (isNaN(showNode.rIndex)) {
      showNode.rIndex = self.aNodes.length;
      self.aNodes[showNode.rIndex] = new Node(showNode);
    } else {
      clearTimeout(self.aNodes[showNode.rIndex].timeRef);
    }
    for (var i in self.aNodes) {
      if (!isParent(self.aNodes[i].elRef, showNode)) {
        clearTimeout(self.aNodes[i].timeRef);
        self.doHide(self.aNodes[i].elRef);
      }
    }
    for (var i in showNode.childNodes) {
      if (showNode.childNodes[i].nodeType == ELEMENT_NODE) {
        showNode.childNodes[i].style.display = 'block';
      }
    }
  }
  this.hideSub = function(hideNode) {
    self.aNodes[hideNode.rIndex].timeRef = setTimeout('oMenu.menuOpen=false;oMenu.doHide(oMenu.aNodes['+hideNode.rIndex+'].elRef)', MENU_CLOSE_MS);
  }
  this.doHide = function(doNode) {
    for (var i in doNode.childNodes) {
      if (doNode.childNodes[i].nodeType == ELEMENT_NODE && doNode.childNodes[i].nodeName == 'UL') {
        doNode.childNodes[i].style.display = 'none';
      }
    }
  }

  this.init=function() {
    $('#menu').mousedown(function() {
      oMenu.menuOpen = !oMenu.menuOpen;
    });
    var li = document.getElementById('menu').getElementsByTagName('li');
    var i = li.length;
    var ul;
    while (i--) {
      ul = li[i].childNodes;
      for(var j in ul) {
        if(ul[j].nodeName!='UL')
          continue;
        ul[j].className=li[i].className='sub';
        li[i].onmouseover=function() {
          if (oMenu.menuOpen)
            oMenu.showSub(this);
        }
        li[i].onmouseup=function() {
          if (oMenu.menuOpen)
            oMenu.showSub(this);
          else
            oMenu.doHide(this);
        }
        li[i].onmouseout=function() {
          if (oMenu.menuOpen)
            oMenu.hideSub(this);
        }
      } // end for
    } // end while
  } // end init()
  
  this.setMessage=function(bError, sMessage) {
    $('#message').text(sMessage);
    if (bError) {
      $('#message').css('color', 'red');
    } else {
      $('#message').css('color', 'black');
      setTimeout(function() {
        $('#message').text('')
      }, 10000);
    }
  }
}
